package com.immortal.core.module.jpa;

import com.immortal.core.module.snowflake.IdWorker;
import org.hibernate.MappingException;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.id.IdentityGenerator;

import java.io.Serializable;

public class WorkIdGenerator extends IdentityGenerator {
    @Override
    public Serializable generate(SharedSessionContractImplementor session, Object object) throws MappingException {
        Object id = IdWorker.getIdStr();
        if (id != null) {
            return (Serializable) id;
        }
        return super.generate(session, object);
    }
}